package com.atguigu.lease.admin.controller.apartment;

import com.atguigu.lease.admin.service.FacilityInfoService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.FacilityInfo;
import com.atguigu.lease.model.enums.ItemTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "配套管理模块")
@RestController
@RequestMapping("/admin/facility")
public class FacilityController {
    @Autowired
    FacilityInfoService service;

    @GetMapping("/list")
    @Operation(summary = "1、根据Type类型查询配套列表")
    public Result<List<FacilityInfo>> list(
            @Parameter(in = ParameterIn.QUERY, description = "配套类型：1-公寓,2-房间")
            @RequestParam(value = "type", required = false) ItemTypeEnum type
    ) {
        LambdaQueryWrapper<FacilityInfo> wrapper = Wrappers.lambdaQuery(FacilityInfo.class);
        wrapper.eq(type != null,FacilityInfo::getType, type);
        List<FacilityInfo> list = service.list(wrapper);
        return Result.ok(list);
    }

    //新增或更新
    @Operation(summary = "2、新增或更新配套")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody FacilityInfo facilityInfo) {
        return Result.ok(service.saveOrUpdate(facilityInfo));
    }

    //删除
    @Operation(summary = "3、根据id删除配套")
    @DeleteMapping("/deleteById")
    public Result deleteById(
            @Parameter(in = ParameterIn.QUERY, description = "主键值")
            @RequestParam Integer id) {
        return Result.ok(service.removeById(id));
    }
}